import React from 'react';
import {
    NavLink,
    withRouter
} from "react-router-dom"
import { Menu, } from 'antd';
import styles from './index.less';

const { SubMenu } = Menu;

class TopMenu extends React.Component {
    state = {
        current: this.getCurrentKey(this.props.location.pathname),
    };

    componentWillReceiveProps(nextProps) {
        if (nextProps.location.pathname !== this.props.location.pathname) {
            this.setState({
                current: this.getCurrentKey(nextProps.location.pathname),
            });
        }
    }
    getCurrentKey(val) {
        if (val.indexOf('algorithm') !== -1) {
            return 'algorithm';
        } else if (val.indexOf('rules') !== -1) {
            return 'rules';
        } else if (val.indexOf('resource') !== -1) {
            return 'resource';
        }
    }
    render() {
      // 获取按钮权限列表
      const buttonList = sessionStorage.getItem('buttonList')
      // 资源库 权限
      let resource=buttonList && buttonList.indexOf('resource') !== -1;
      // 数据中心 权限
      let data_center=buttonList && buttonList.indexOf('data_center') !== -1;
      // 模型中心 权限
      let model_center=buttonList && buttonList.indexOf('model_center') !== -1;
      // 字典 权限
      let word_library=buttonList && buttonList.indexOf('word_library') !== -1;
      // 词向量 权限
      let word_vector=buttonList && buttonList.indexOf('word_vector') !== -1;
        return (
            <Menu selectedKeys={[this.state.current]} mode="horizontal" className={styles.defineMenu}>
              {(data_center || model_center) && <Menu.Item key="algorithm">
                <NavLink to="/algorithm/dataCenter">算法模型</NavLink>
              </Menu.Item>}
                {/* <Menu.Item key="rules">
                    <NavLink to='/rules'>规则模型</NavLink>
                </Menu.Item> */}
              {(word_library || word_vector) && <Menu.Item key="resource">
                <NavLink to='/resource/dictionary'>资源库</NavLink>
              </Menu.Item>}
            </Menu>
        );
    }
}
export default withRouter(TopMenu)
